<template>
  <div id="barrage" class="1"></div>
</template>

<script>
  export default {
    data(){
      return {
        arrays: ['1111','2222','3333','4444','5555','6666','7777'],
        num: 0,
        fun: {},
        domEl: undefined,
      }
    },
    //
    methods: {
      //
      initEvent(){
        let eop2 = document.querySelector('.e-op2');
        let eop1 = document.querySelector('.e-op1');
        let that = this;
        // eop1 结束
        eop1 && eop1.addEventListener("webkitAnimationEnd", function() {
          //
          let op1ClassName = this.className
          op1ClassName = op1ClassName.replace('e-op1', 'e-op2')
          this.className = op1ClassName
          //
          if(that.num >= that.arrays.length-1){
            that.num = 0;
          }else{
            that.num++;
          }
          that.fun.handleO(2);
        });
        // eop2 结束
        eop2 && eop2.addEventListener("webkitAnimationEnd", function() {
          eop2.remove();
        });
      }
    },
    //
    mounted(){
      //
      this.domEl = document.querySelector('#barrage');
      // 定义函数
      this.fun.handleO =(num) =>{
        //
        let htmlstr = '<div class="op e-op1">'+this.arrays[this.num]+'</div>';
        //
        this.domEl.innerHTML = this.domEl.innerHTML + htmlstr;
        // 事件监听
        this.initEvent();
      }
      // 调用
      this.fun.handleO();
    }
  }
</script>
<style>
  body,html{
    margin: 0;
    padding: 0;
    -webkit-box-sizing:border-box;
    font-size: 1rem;
    font-family: "微软雅黑";
    height: 100%;
    background-color: #F7F7F7 !important;
  }
  #barrage {
    height: 56px;
    z-index: 9998;
    position: absolute;
    color: #fff;
    font-size: 12px;
    margin-top: 200px;
    width: 100%;
    text-align: center;
  }
  .op {
    background: #000;
    text-align: center;
    border-radius: 10px;
    display: inline-block;
    position: absolute;
    padding: 10px;
    transform: translateX(-50%);
    -webket-transform: translateX(-50%);
  }
  .op span{
    color: #FFE168;
  }
  .e-op1{
    opacity: 0;
    top: 50px;
    animation:fadeIn 2.2s linear;
    -webkit-animation:fadeIn 2.2s linear;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
  }
  .e-op2{
    opacity: 0.8;
    top: 0;
    animation:fadeOut 2.1s linear;
    -webkit-animation:fadeOut 2.1s linear;
    animation-fill-mode:forwards;
    -webkit-animation-fill-mode:forwards;
  }
  @-webkit-keyframes fadeIn {
    0% {
      /*transform:scale(0.8,0.8);
      -webkit-transform:scale(0.8,0.8);*/
    }
    100% {
      opacity: 0.8;
      top: 0;
      /* transform:scale(0.8,0.8);
       -webkit-transform:scale(0.8,0.8);*/
    }
  }

  @-webkit-keyframes fadeOut {
    0% {
      /*   transform:scale(0.8,0.8);
         -webkit-transform:scale(0.8,0.8);*/
    }
    100% {
      opacity: 0;
      top: -50px;
      /* transform:scale(0.5,0.5);
       -webkit-transform:scale(0.5,0.5);*/
    }
  }
</style>
